#!/bin/sh

while true
do
  curl http://dingyue.me/register_log.txt 2>/dev/null >tmp.log
  if [ $? -eq 0 ]
  then
    remote_line=`cat tmp.log | wc -l`
    if [ $remote_line -ne 0 ]
    then
      local_line=`cat register_log.txt | wc -l`
      let diff_line=$remote_line-$local_line
      date >>register.log
      echo "remote_line=$remote_line local_line=$local_line diff_line=$diff_line" >>register.log
      if [ $diff_line -ne 0 ]
      then
        tail -n $diff_line tmp.log | php ./run_sync_register.php >>register.log 2>&1
        mv tmp.log register_log.txt
      fi
    fi
  fi
  sleep 10
done
